'use strict'

angular.module('mainApp')
.controller('personDetailCtrl',function($scope, tjzHttp, constant, ngDialog, $stateParams, $state){
    var userId = $stateParams.userId;
    var init = function(){
        tjzHttp.postRequest(constant.url + '/userinfo',{userId:userId}).then(function(res){
            if(res.data.code == 0){
                $scope.info = res.data.data;
                for(var i=0;i<$scope.info.list.length;i++){
                    $scope.info.list[i].date = $scope.info.list[i].date.split('.0')[0];
                }
            }
        })
    }
    $scope.favorite = function(){
        tjzHttp.postRequest(constant.url + '/create/favorite/user', {favoriteUserId:userId}).then(function(res){
            if(res.data.code == 0){
                ngDialog.open({
                    template: 'template/dialog.html',
                    width: 600,
                    controller: ['$scope',function($scope){
                        $scope.dialogTitle = '淘家政提示';
                        $scope.dialogContent = '收藏成功';
                        $scope.yes = function(){
                            $scope.closeThisDialog();
                        }
                    }]
                });
            }else{
                var message = res.data.message;
                ngDialog.open({
                    template: 'template/dialog.html',
                    width: 600,
                    data: {
                        message: message
                    },
                    controller: ['$scope',function($scope){
                        var message = $scope.ngDialogData.message;
                        $scope.dialogTitle = '淘家政提示';
                        $scope.dialogContent = message;
                        $scope.yes = function(){
                            $scope.closeThisDialog();
                        }
                    }]
                });
            }
        })
    }
    $scope.save = function(){
        var data = {
            score: $scope.score,
            evaluate: $scope.evaluates,
            evaluateUserId: userId
        }
        tjzHttp.postRequest(constant.url + '/create/user/evaluate', data).then(function(res){
            if(res.data.code == 0){
                ngDialog.open({
                    template: 'template/dialog.html',
                    width: 600,
                    controller: ['$scope',function($scope){
                        $scope.dialogTitle = '淘家政提示';
                        $scope.dialogContent = '评价成功';
                        $scope.yes = function(){
                            $scope.closeThisDialog();
                        }
                    }]
                }).closePromise.then(function(){
                    $state.reload();
                });
            }else{
                var message = res.data.message;
                ngDialog.open({
                    template: 'template/dialog.html',
                    width: 600,
                    data: {
                        message: message
                    },
                    controller: ['$scope',function($scope){
                        var message = $scope.ngDialogData.message;
                        $scope.dialogTitle = '淘家政提示';
                        $scope.dialogContent = message;
                        $scope.yes = function(){
                            $scope.closeThisDialog();
                        }
                    }]
                });
            }
        })
    }
    init();

})